<template>
  <div
    class="flex flex-col items-center justify-center min-h-screen bg-gray-100"
  >
    <div class="bg-white p-8 rounded shadow max-w-sm w-full">
      <el-form :model="form" ref="formRef" label-width="100px">
        <el-form-item
          label="账号"
          prop="account"
          :rules="[
            {
              message: '请输入账号',
              required: true,
            },
          ]"
        >
          <el-input
            v-model="form.account"
            autocomplete="off"
            placeholder="请输入账号"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="密码:"
          prop="password"
          required
          :rules="{
            message: '请输入密码',
            required: true,
          }"
        >
          <el-input
            type="password"
            v-model="form.password"
            autocomplete="off"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleLogin" class="w-full">{{
            submitText
          }}</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup lang="ts">
import { FormInstance } from "element-plus";

defineProps<{
  submitText: string;
}>();

const emit = defineEmits<{
  submit: [any];
}>();

const form = ref({
  account: "",
  password: "",
});

const formRef = ref<FormInstance>();
const handleLogin = () => {
  formRef.value?.validate(async (e) => {
    if (e) {
      emit("submit", form.value);
    }
  });
};
</script>
